/************************************************
  class Parser.
  a Parser class that takes a file and parses it into tokens
  Rules: ignore blanks, tabs and whatever


************************************************/

#pragma once
#include <string>
//#include <vector>
#include <queue>
#include "InputLine.h"
#include "Token.h"
#include <fstream>


class Parser{

public:
	Parser();
	virtual ~Parser();


	// virtual to allow other kinds of stream (file data) to be handled
	// consumer producer design
	// the user asks for tokens - the parser get them by line (a bunch)
	// sends a NULL when tokens are over
	//not really a const - only to the user
	virtual void getToken(Token& tok); 

	// virtual to allow opening files in formats other then ascii.
	virtual bool setFile(const std::string fileName);

	void setInputLine(const InputLine * const in);

	//getline would work only if pareser is ready.
	bool isParserReady() const;

protected:
	bool inputLineSet;
	bool fileOpened;

	//int totalNumOfToken;///////////////////////////////////// ?????????????????????????????????????????
	//map int-int to count tokens in each line
	std::ifstream file;
	const InputLine * input;
//	std::vector<Token *> tokens;
	std::queue<Token *> tokens;


private:
	static Token EOFToken;
	static Token BADToken;

	void readTokens();
	int lineNum;

	Parser(const Parser& parser);
	const Parser& operator=(const Parser& parser);

};